package cn.codinglives.ssoplus.service;

import com.google.common.collect.Maps;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 使用第三方code获取用户信息.
 * @author feihu.wang
 */
@Service
public class ThirdCodeService {


    @Resource
    private RestTemplate restTemplate;

    public String getUserKey(String url, String code) {
        Map<String,String> paramMap = Maps.newHashMap();
        paramMap.put("code", code);
        ResponseEntity<String> response = restTemplate.getForEntity(url, String.class, paramMap);
        if (response.getStatusCode() == HttpStatus.OK) {
            return response.getBody();
        }
        return "";
    }
}
